package panel;

import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.geom.AffineTransform;

import javax.swing.JPanel;

@SuppressWarnings("serial")
public class Ajou extends JPanel{
	private boolean showText;
	private double angle;
	
	public boolean isShowText() {
		return showText;
	}

	public void setShowText(boolean showText) {
		this.showText = showText;
	}

	public void adjustAngle(double angle) {
		this.angle += angle;
		if (this.angle == 360)
			this.angle = 0;
	}

	@SuppressWarnings("static-access")
	public void paintComponent(Graphics g) {

		Toolkit winTool = this.getToolkit();
		Image buffer = createImage(336, 336);
		Graphics bufferG = buffer.getGraphics();

		bufferG.drawImage(winTool.getImage(".\\Images\\Loading_Ajou.png"), 0, 0, this);
		
		if(showText)
			bufferG.drawImage(winTool.getImage(".\\Images\\Loading_Text.png"), 0, 0, this);
		
		g.drawImage(buffer, 0, 0, this);

		/*reference : https://www.daniweb.com/software-development/java/threads/352101/java-graphics-rotation*/
		Graphics2D g2d = (Graphics2D) g;
		AffineTransform affTransform = g2d.getTransform();
		AffineTransform transform = (AffineTransform) (affTransform.clone());
		g2d.transform(transform.getRotateInstance(Math.toRadians(angle), this.getWidth() / 2, this.getHeight() / 2));

		Image image = winTool.getImage(".\\Images\\Loading_Rotate.png");
		g2d.drawImage(image, 0, 0, null);
		g2d.setTransform(affTransform);
		//end of reference
		
		setOpaque(false);
		super.paintComponent(g);
	}
}
